package com.kfm.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/responseB")
public class ResponseBServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("responseB service");
        // 响应一个html页面
        resp.setCharacterEncoding("UTF-8");
        // 告诉浏览器响应的是html页面 要解析html标签
        resp.setHeader("content-type", "text/html;charset='UTF-8'");
        resp.setContentType("text/html;charset='utf-8'");

        PrintWriter writer = resp.getWriter();
        writer.write("<h1>hello</h1>");
    }
}
